package cn.maszy.action.projectmanagement;
import java.util.List;

import net.sourceforge.stripes.action.SessionScope;
import org.springframework.beans.factory.annotation.Autowired;
import cn.maszy.common.BaseAction;
import cn.maszy.common.Pager;
import cn.maszy.common.Transcoding;
import cn.maszy.model.projectmanagement.B_T_Ufp_EngineerCategory;
import cn.maszy.model.projectmanagement.B_T_Ufp_EngineerPosition;
import cn.maszy.model.systemsetting.B_T_Ufp_Material;
import cn.maszy.service.projectmanagement.B_T_Ufp_EngineerCategoryService;
import cn.maszy.service.projectmanagement.B_T_Ufp_EngineerPositionService;

@SessionScope
public class EngineerPositionAction extends BaseAction<B_T_Ufp_EngineerPosition> {
	/**
	 * 版本控制信息
	 */
	private static final long serialVersionUID = 6179604301571294802L;
	private B_T_Ufp_EngineerPosition b_T_Ufp_EngineerPosition;
	@Autowired
	private B_T_Ufp_EngineerCategoryService b_T_Ufp_EngineerCategoryService;
	@Autowired
	private B_T_Ufp_EngineerPositionService b_T_Ufp_EngineerPositionService;
	private String checkIds;
	private String status;
	private String flag;
	//是否可以修改
	private String isupdate;
	private List<B_T_Ufp_EngineerPosition> list_b_T_Ufp_EngineerPosition;
	/*******************STRUTS ACTION METHOD*************************/
	public String engineerPositionDelete() throws Exception {
		int i=b_T_Ufp_EngineerPositionService.delete(checkIds);
		if(i>0)
		{
			if("delete".equals(flag))
			{
					return ajaxForwardSuccess(getText("msg.operation.success"), "","EngineerPositionbuweiList", "", "");	
			}
					return ajaxForwardSuccess(getText("msg.operation.success"), "","", "forward", "projectmanagement/EngineerPosition_engineerPositionList");
		}
		else
		{
			return ajaxForwardError(getText("msg.operation.failure"));
		}
	}
	public String engineerPositionUpdate() throws Exception {
		int i=b_T_Ufp_EngineerPositionService.update(b_T_Ufp_EngineerPosition);
		if(i>0)
		return ajaxForwardSuccess(getText("msg.operation.success"), "","EngineerPositionbuweiList", "closeCurrent", "");
		return ajaxForwardError(getText("msg.operation.failure"));
	}
	public String engineerPositionList() throws Exception {
		//工程报价时传工程uuid，name，type查询条件只显示当前工程所属的数据
//		if(b_T_Ufp_EngineerPosition!=null&&!"".equals(b_T_Ufp_EngineerPosition))
//		{
//			flag =new String(flag.getBytes("ISO8859_1"),"utf-8");
//			String flag1[]=flag.split(",");
//			b_T_Ufp_EngineerPosition.setEngineeringUuid(flag1[0]);
//			b_T_Ufp_EngineerPosition.setEngineeringName(flag1[1]);
//			b_T_Ufp_EngineerPosition.setEngineeringType(flag1[2]);
//		}
//		else
//		{
			if(flag !=null&&!"".equals(flag))
			{
				b_T_Ufp_EngineerPosition = new B_T_Ufp_EngineerPosition();
				flag =Transcoding.getcode(request, flag);
//				flag =new String(flag.getBytes("ISO8859_1"),"GBK");
				String flag1[]=flag.split(",");
				b_T_Ufp_EngineerPosition.setEngineeringUuid(flag1[0]);
				b_T_Ufp_EngineerPosition.setEngineeringName(flag1[1]);
				b_T_Ufp_EngineerPosition.setEngineeringType(flag1[2]);
			}
//		}
		list_b_T_Ufp_EngineerPosition=b_T_Ufp_EngineerPositionService.select(b_T_Ufp_EngineerPosition);
		if(list_b_T_Ufp_EngineerPosition!=null&&list_b_T_Ufp_EngineerPosition.size()>0)
		{
			b_T_Ufp_EngineerPosition=list_b_T_Ufp_EngineerPosition.get(0);
		}
		return SUCCESS;
	}
	public String EngineerPositionbuweiList() throws Exception {
//		if(b_T_Ufp_EngineerPosition!=null&&!"".equals(b_T_Ufp_EngineerPosition))
//		{
//			flag =new String(flag.getBytes("ISO8859_1"),"utf-8");
//			String flag1[]=flag.split(",");
//			b_T_Ufp_EngineerPosition.setEngineeringUuid(flag1[0]);
//			b_T_Ufp_EngineerPosition.setEngineeringName(flag1[1]);
//			b_T_Ufp_EngineerPosition.setEngineeringType(flag1[2]);
//		}
//		else
//		{
			if(flag !=null&&!"".equals(flag))
			{
				b_T_Ufp_EngineerPosition = new B_T_Ufp_EngineerPosition();
				flag =Transcoding.getcode(request, flag);
//				flag =new String(flag.getBytes("ISO8859_1"),"GBK");
				String flag1[]=flag.split(",");
				b_T_Ufp_EngineerPosition.setEngineeringUuid(flag1[0]);
				b_T_Ufp_EngineerPosition.setEngineeringName(flag1[1]);
				b_T_Ufp_EngineerPosition.setEngineeringType(flag1[2]);
			}
//		}
		list_b_T_Ufp_EngineerPosition=b_T_Ufp_EngineerPositionService.select(b_T_Ufp_EngineerPosition);
		if(list_b_T_Ufp_EngineerPosition!=null&&list_b_T_Ufp_EngineerPosition.size()>0)
		{
			b_T_Ufp_EngineerPosition=list_b_T_Ufp_EngineerPosition.get(0);
		}
		return SUCCESS;
	}
	public String engineerPositionDetail() throws Exception {
		if(b_T_Ufp_EngineerPosition==null){
			b_T_Ufp_EngineerPosition=b_T_Ufp_EngineerPositionService.selectOne("");
			if(flag !=null&&!"".equals(flag)){
				b_T_Ufp_EngineerPosition = new B_T_Ufp_EngineerPosition();
				flag =Transcoding.getcode(request, flag);
//				flag =new String(flag.getBytes("ISO8859_1"),"GBK");
				String flag1[]=flag.split(",");
				b_T_Ufp_EngineerPosition.setEngineeringUuid(flag1[0]);
				b_T_Ufp_EngineerPosition.setEngineeringName(flag1[1]);
				b_T_Ufp_EngineerPosition.setEngineeringType(flag1[2]);
				}
		}else{
			//点击修改页面是，如果有关联数据，不让修改部位名称。
			B_T_Ufp_EngineerCategory b_T_Ufp_EngineerCategory =new B_T_Ufp_EngineerCategory();
			b_T_Ufp_EngineerCategory.setPositionUuid(b_T_Ufp_EngineerPosition.getUuid());
			List<B_T_Ufp_EngineerCategory> list_b_T_Ufp_EngineerCategory=b_T_Ufp_EngineerCategoryService.select(b_T_Ufp_EngineerCategory);
			if(list_b_T_Ufp_EngineerCategory.size()>0)
			{
				return ajaxForwardError(getText("此类别下有数据无法修改"));
			}
			b_T_Ufp_EngineerPosition=b_T_Ufp_EngineerPositionService.selectOne(b_T_Ufp_EngineerPosition.getUuid());
		}
		return SUCCESS;
	}
	
/********************* class set/get ****************************/
	
	public B_T_Ufp_EngineerPosition getB_T_Ufp_EngineerPosition() {
		return b_T_Ufp_EngineerPosition;
	}

	public void setB_T_Ufp_EngineerPosition(B_T_Ufp_EngineerPosition b_T_Ufp_EngineerPosition) {
		this.b_T_Ufp_EngineerPosition = b_T_Ufp_EngineerPosition;
	}
	
	public String getCheckIds() {
		return checkIds;
	}

	public void setCheckIds(String checkIds) {
		this.checkIds = checkIds;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public List<B_T_Ufp_EngineerPosition> getList_b_T_Ufp_EngineerPosition() {
		return list_b_T_Ufp_EngineerPosition;
	}
	public void setList_b_T_Ufp_EngineerPosition(
			List<B_T_Ufp_EngineerPosition> list_b_T_Ufp_EngineerPosition) {
		this.list_b_T_Ufp_EngineerPosition = list_b_T_Ufp_EngineerPosition;
	}
	public String getFlag() {
		return flag;
	}
	public void setFlag(String flag) {
		this.flag = flag;
	}
	public String getIsupdate() {
		return isupdate;
	}
	public void setIsupdate(String isupdate) {
		this.isupdate = isupdate;
	}
}
